package com.keyancompany.zhongbaopingtai.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.model.CommentModel;
import com.keyancompany.zhongbaopingtai.model.SearchRecordModel;
import com.keyancompany.zhongbaopingtai.weight.CircleImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by firefox on 2016/6/15.
 */
public class CircleThemeDetailAdapter extends ListAdapter<CommentModel> {

    private View.OnClickListener clickListener;

    public void setClickListener(View.OnClickListener listener) {
        this.clickListener = listener;
    }

    public CircleThemeDetailAdapter(Context ctx) {
        super(ctx);
    }

    @Override
    public int getContentViewId() {
        return R.layout.item_circle_theme;
    }

    @Override
    public HolderView getHoldView(int position, View contentView, ViewGroup parent) {
        CircleThemeHolder hold = new CircleThemeHolder();
        hold.title = (TextView) contentView.findViewById(R.id.user_name);
        hold.time = (TextView) contentView.findViewById(R.id.time);
        hold.goTheme = (TextView) contentView.findViewById(R.id.go_theme);
        hold.content = (TextView) contentView.findViewById(R.id.content);
        hold.avator = (CircleImageView) contentView.findViewById(R.id.user_avatar);
        return hold;
    }

    @Override
    public void setItemView(final int position, HolderView contentView, final CommentModel item) {
        CircleThemeHolder hold = (CircleThemeHolder) contentView;
        if (position == 0) {
            hold.goTheme.setText("评论");
            ImageLoader.getInstance().displayImage(item.getHeadpic(), hold.avator);
            hold.avator.setVisibility(View.VISIBLE);
            hold.content.setText(item.getMsg());
            hold.time.setText(item.getCreatetime());
            hold.title.setText(item.getUsername());
        } else {
            hold.goTheme.setText("回复");
            hold.avator.setVisibility(View.GONE);
            hold.content.setText(item.getCommentmsg());
            hold.time.setText(item.getCreatetime());
            hold.title.setText(item.getUsername()+ " 回复 "+item.getAnswerUsername());
        }

        hold.goTheme.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (clickListener != null) {
                    view.setTag(position);
                    clickListener.onClick(view);
                }
            }
        });

    }

    class CircleThemeHolder extends HolderView {

        TextView title;

        TextView content;

        TextView time;

        TextView goTheme;

        CircleImageView avator;

    }

}
